//
//  SAPAudioTwoTableViewCell.m
//  CarsHome
//
//  Created by dapeng on 15/12/16.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "SAPAudioTwoTableViewCell.h"

@implementation SAPAudioTwoTableViewCell
- (void)dealloc {
    [_name release];
    [_descrition release];
    [_imgurl release];
    [_bigImgurl release];
    [_ermai release];
    [_shijian release];
    [_program_live_time release];
    [_program_join_num release];
    [_program_file_size release];
    [_program_time_length release];
    [_program_title release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.program_live_time = [[UILabel alloc] init];
        self.program_join_num = [[UILabel alloc] init];
        self.program_file_size = [[UILabel alloc] init];
        self.program_time_length = [[UILabel alloc] init];
        self.program_title = [[UILabel alloc] init];
        self.ermai = [[UIImageView alloc] init];
        self.shijian = [[UIImageView alloc] init];
      
        [_ermai release];
        [_shijian release];
        [_program_live_time release];
        [_program_join_num release];
        [_program_file_size release];
        [_program_time_length release];
        [_program_title release];
        [self addSubview:self.program_title];
        [self addSubview:self.program_live_time];
        [self addSubview:self.program_time_length];
        [self addSubview:self.program_join_num];
        [self addSubview:self.program_file_size];
        [self addSubview:self.ermai];
        [self addSubview:self.shijian];
        
        [_ermai release];
        [_shijian release];
        [_program_live_time release];
        [_program_join_num release];
        [_program_file_size release];
        [_program_time_length release];
        [_program_title release];
        
        
    }return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    
    
    CGFloat join_numWidth = [self getWidthWithText:_program_join_num.text withFont:14];
    CGFloat time_lengthWidth = [self getWidthWithText:_program_time_length.text withFont:14];
    
    self.program_live_time.frame = CGRectMake(10, 10, 100, 30);
    self.program_title.frame = CGRectMake(110, 10, SCREEN_SIZE.width - 110, 30);
    self.ermai.frame = CGRectMake(10, 40, 15, 15);
    self.program_join_num.frame = CGRectMake(35, 40, join_numWidth, 20);
    self.shijian.frame = CGRectMake(join_numWidth + 70, 40, 15, 15);
    self.program_time_length.frame = CGRectMake(90 + join_numWidth, 40, time_lengthWidth, 20);
    self.program_file_size.frame = CGRectMake(join_numWidth + 180, 40, 80, 20);
    
}
- (void)setTwoModel:(SAPAudioTwoModel *)twoModel {
    if (_twoModel != twoModel) {
        [_twoModel release];
        _twoModel = [twoModel retain];
    }
    self.ermai.image = [UIImage imageNamed:@"ermai"];
    self.shijian.image = [UIImage imageNamed:@"liulanlishi2"];
    
    self.program_live_time.text = twoModel.program_live_time;
    self.program_title.text = twoModel.program_title;

    self.program_join_num.text = [NSString stringWithFormat:@"%ld", twoModel.program_join_num];
    
    self.program_join_num.textColor = [UIColor grayColor];
    self.program_time_length.textColor = [UIColor grayColor];
    self.program_file_size.textColor = [UIColor grayColor];
    self.program_time_length.text = twoModel.program_time_length;
    self.program_file_size.text = twoModel.program_file_size;
    self.program_join_num.font = [UIFont systemFontOfSize:14];
    self.program_time_length.font = [UIFont systemFontOfSize:14];
    self.program_file_size.font = [UIFont systemFontOfSize:14];
    
}

- (CGFloat)getWidthWithText:(NSString *)text withFont:(CGFloat)font {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.width;
}

- (CGFloat)getHeightWithText:(NSString *)text withFont:(CGFloat)font {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(0, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
